var t = require("../../../utils/http.js"), e = getApp();

Page({
    data: {
        choiceAll: !1,
        status: 10,
        orderList: [],
        pages: [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ],
        page: 0,
        diff_order_id: "1",
        out_trade_no: "",
        order_no: "",
        keyword: "",
        count: 0
    },
    choiceTap: function(t) {
        var e = t.currentTarget.dataset.index, o = this.data.orderList, a = o, s = this.data.choiceAll;
        a[e].selected = !a[e].selected;
        for (var r = 0; r < a.length; r++) 0 == a[r].selected && (s = !1);
        o = a, this.setData({
            orderList: o,
            choiceAll: s
        });
    },
   
    message: function() {
        var e = this;
        t.post("/app/dock/unread_message", {}, !1, function(t) {
            console.log(t);
            var o = t.count;
            e.setData({
                count: o > 99 ? "99+" : o
            });
        });
    },
    choiceAllTap: function() {
        for (var t = !this.data.choiceAll, e = this.data.orderList, o = e, a = 0; a < o.length; a++) o[a].selected = t;
        e = o, this.setData({
            choiceAll: t,
            orderList: e
        });
    },
    onLoad: function(t) {
        var o = this, a = this;
        var i = t.status;
        console.log(i, "status"), i || (i = 10), this.setData({
            orderList: [],
            pages: [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ],
            status: i
        });
        this.getData({}, i);
    },

    onShow: function() {
        var t = this.data.ischang, e = this.data.status;
        e || (e = 10), t && (this.setData({
            orderList: [],
            pages: [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ],
            status: 10,
            keyword: ""
        }), this.getData({}, 2));
    },

    getData: function(e, o) {
        var a = this, s = this, r = s.data.pages, n = r[o] + 1;
        console.log(n, "page当前第几页"), e.status = o, e.page = n, e.num = 10;
        t.post("/app/dock/OrderList", e, !0, function(t) {
            console.log(t, "getshipAddressdata"), (t = null == t.data ? t : t.data).forEach(function(e, o) {
                t[o].sender_city = null == e.sender_region ? e.order_info.sender_region.split(",")[1] : e.sender_region.split(",")[1], 
                t[o].receive_city = null == e.receive_region ? e.order_info.receive_region.split(",")[1] : e.receive_region.split(",")[1];
            }), console.log(t.data, "data.data");
            for (var e = 0; e < t.length; e++) t[e].isTouchMove = !1;
            var i = s.data.orderList, d = i;
            if (null != d && null != d || (d = []), t.length > 0) {
                console.log(t.length, "data.length一页10条"), r[o] = n, console.log(r[o], "pages[status]第几页"), 
                console.log("循环了");
                for (var c = 0; c < t.length; c++) d.push(t[c]);
                i = d, console.log(i, "dataList填充新数据后的"), s.setData({
                    orderList: i,
                    pages: r
                }), console.log(a.data.orderList, "returndataList");
            } else wx.showToast({
                title: "已经到底啦~",
                icon: "none"
            });
        });
    },
    serviceTap: function() {
        e.officialCall();
    },
    search: function(t) {
        var e = t.detail.value, o = this.data.status;
        this.setData({
            orderList: [],
            pages: [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ],
            status: o,
            keyword: e
        }), this.getData({
            keyword: e
        }, o);
    },
    getSelectedIDs: function() {
        var t = this.data.orderList, e = [], o = "";
        return t.forEach(function(t) {
            t.selected ? o += "," + t.id : e.push(t);
        }), "" == o ? (wx.showToast({
            title: "请勾选至少一笔订单！",
            icon: "none"
        }), !1) : {
            ids: o = o.substring(1, o.length),
            list: e
        };
    },
    delchajia: function(e) {
        var o = this;
        wx.showModal({
            title: "系统提醒",
            content: "真的要删除该订单吗？",
            success: function(a) {
                if (a.confirm) {
                    var s = e.currentTarget.dataset.index, r = o.data.orderList, n = r, i = n[s].id;
                    t.post("/app/dock/DelDiffOrder", {
                        diff_order_id: i
                    }, !0, function(t) {
                        wx.showToast({
                            title: "删除成功"
                        }), n.splice(s, 1), r = n, o.setData({
                            orderList: r
                        }), wx.removeStorageSync("/app/dock/OrderList" + JSON.stringify({
                            status: o.data.status
                        }));
                    });
                }
            }
        });
    },
    delete: function(e) {
        var o = this;
        wx.showModal({
            title: "系统提醒",
            content: "真的要删除该订单吗？",
            success: function(a) {
                if (a.confirm) {
                    var s = e.currentTarget.dataset.index, r = o.data.orderList, n = r;
                    console.log(r, "-----orderList"), console.log(n, "------statusOrderList");
                    var i = n[s].id;
                    t.post("/app/dock/DelOrder", {
                        order_id: i
                    }, !0, function(t) {
                        wx.showToast({
                            title: "删除成功"
                        }), n.splice(s, 1), r = n, o.setData({
                            orderList: r
                        }), console.log(r, "======orderListorderList"), wx.removeStorageSync("/app/dock/OrderList" + JSON.stringify({
                            status: o.data.status
                        }));
                    });
                }
            }
        });
    },
    coll: function(e) {
        wx.showModal({
            title: "系统提醒",
            content: "确定要催发快递吗？",
            success: function(o) {
                if (o.confirm) {
                    var a = e.currentTarget.dataset.id;
                    t.post("/app/dock/CollExpress", {
                        order_id: a
                    }, !0, function(t) {
                        wx.showToast({
                            title: "催发快递成功"
                        });
                    });
                }
            }
        });
    },
    deleteAll: function() {
        var e = this, o = e.getSelectedIDs();
        if (console.log(o, "----info"), !o) return !1;
        wx.showModal({
            title: "系统提醒",
            content: "真的要删除所有选中的订单吗？",
            success: function(a) {
                var s = e.data.orderList;
                a.confirm && t.post("/app/dock/DelOrder", {
                    order_id: o.ids
                }, !0, function(t) {
                    wx.showToast({
                        title: "删除成功"
                    }), s[e.data.status] = o.list, console.log(o.list, "----info.list"), e.setData({
                        orderList: s
                    }), wx.removeStorageSync("/app/dock/OrderList" + JSON.stringify({
                        status: e.data.status
                    }));
                });
            }
        });
    },
    applyCancelTap: function(t) {
        var e = t.currentTarget.dataset.index, o = this.data.orderList[e].id;
        wx.navigateTo({
            url: "/pages/reason/reason?order_id=" + o
        });
    },
    applyAllCancelTap: function(t) {
        var e = this.getSelectedIDs();
        if (!e) return !1;
        wx.navigateTo({
            url: "/pages/reason/reason?order_id=" + e.ids
        });
    },
    gotousu: function(t) {
        var e = t.currentTarget.dataset.order_no;
        wx.navigateTo({
            url: "/pages/complaint/complaint?order_no=" + e
        });
    },
    goorder: function(t) {
        var e = t.currentTarget.dataset.id;
        wx.navigateTo({
            url: "/pages/order_detail/detail?orderid=" + e
        });
    },
    cancelOrder: function(e) {
        var o = this;
        wx.showModal({
            title: "系统提醒",
            content: "真的要申请撤销该订单吗？",
            success: function(a) {
                if (a.confirm) {
                    var s = e.currentTarget.dataset.index, r = o.data.orderList, n = r, i = n[s].id;
                    t.post("/app/dock/CancelOrder", {
                        order_id: i
                    }, !0, function(t, e) {
                        wx.showToast({
                            title: e
                        }), n.splice(s, 1), r = n, o.setData({
                            orderList: r
                        }), wx.removeStorageSync("/app/dock/OrderList" + JSON.stringify({
                            status: o.data.status
                        }));
                    });
                }
            }
        });
    },
    cancelOrderAll: function() {
        var e = this, o = e.getSelectedIDs();
        if (!o) return !1;
        wx.showModal({
            title: "系统提醒",
            content: "真的要申请撤销所有选中的订单吗？",
            success: function(a) {
                a.confirm && t.post("/app/dock/CancelOrder", {
                    order_id: o.ids
                }, !0, function(t, a) {
                    wx.showToast({
                        title: a
                    });
                    var s = e.data.orderList;
                    s = o.list, e.setData({
                        orderList: s
                    }), wx.removeStorageSync("/app/dock/OrderList" + JSON.stringify({
                        status: e.data.status
                    }));
                });
            }
        });
    },
    pay: function(t) {
        var e = t.currentTarget.dataset.index, o = this.data.orderList[e].id;
        wx.navigateTo({
            url: "/pages/order_detail/detail?order_id=" + o
        });
    },
    tabChoose: function(t) {
        var e = t.currentTarget.dataset.orderindex, o = t.currentTarget.dataset.index, a = this.data.orderList;
        a[e].tabIndex = o, this.setData({
            orderList: a
        });
    },
    statusTabChoose: function(t) {
        var e = t.currentTarget.dataset.index;
        this.setData({
            status: e,
            choiceAll: !1,
            orderList: [],
            pages: [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ],
            page: "0",
            keyword: ""
        }), this.getData({}, e);
    },
    onReachBottom: function() {
        var t = this.data.status;
        this.getData({
            status: t
        }, t);
    },
    copyDingdan: function(t) {
        var e = t.currentTarget.dataset.index, o = this.data.orderList, a = o;
        a[e].id;
        var s = a[e].order_no;
        wx.setClipboardData({
            data: s,
            success: function(t) {
                wx.hideLoading({
                    success: function(t) {}
                }), wx.showModal({
                    title: "提示",
                    content: "复制成功",
                    showCancel: !1,
                    success: function(t) {
                        t.confirm ? console.log("确定") : t.cancel && console.log("取消");
                    }
                });
            }
        });
    },
    copyYundan: function(t) {
        var e = t.currentTarget.dataset.index, o = this.data.orderList, a = o;
        var s = a[e], r = (s.id, a[e].yundan);
        wx.setClipboardData({
            data: r,
            success: function(t) {
                wx.hideLoading({
                    success: function(t) {}
                }), wx.showModal({
                    title: "提示",
                    content: "复制成功",
                    showCancel: !1,
                    success: function(t) {
                        t.confirm ? console.log("确定") : t.cancel && console.log("取消");
                    }
                });
            }
        });
    },
    isforwar: function(t) {
        var e = t.currentTarget.dataset.order_no;
        this.setData({
            isforward: !0,
            forwar_order_no: e
        });
    },
    colsefor: function() {
        this.setData({
            isforward: !1,
            forwar_order_no: ""
        });
    },
    goforward: function() {
        var e = this, o = this.data.forwar_order_no;
        t.post("/app/dock/forward", {
            order_no: o
        }, !0, function(t) {
            e.setData({
                isforward: !1,
                forwar_order_no: "",
                orderList: [],
                pages: [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ],
                status: 2
            }), e.getData({}, 2);
        });
    },
    copychajiaDingdan: function(t) {
        var e = t.currentTarget.dataset.index, o = this.data.orderList, a = o;
        var s = a[e], r = (s.id, a[e].out_trade_no);
        wx.setClipboardData({
            data: r,
            success: function(t) {
                wx.showModal({
                    title: "提示",
                    content: "复制成功",
                    success: function(t) {
                        t.confirm ? console.log("确定") : t.cancel && console.log("取消");
                    }
                });
            }
        });
    }
});